package com.zzyl.nursing.mapper;

import java.util.List;
import com.zzyl.nursing.domain.FamilyMember;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.FamilyMemberEder;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.vo.DeviceDataVoo;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.DeviceDataVoo;
import com.zzyl.nursing.vo.FamilyMemberVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import com.zzyl.nursing.vo.LoginVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 老人家属Mapper接口
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@Mapper
public interface FamilyMemberMapper extends BaseMapper<FamilyMember>
{
    /**
     * 查询老人家属
     * 
     * @param id 老人家属主键
     * @return 老人家属
     */
    public FamilyMember selectFamilyMemberById(Long id);

    /**
     * 查询老人家属列表
     * 
     * @param familyMember 老人家属
     * @return 老人家属集合
     */
    public List<FamilyMember> selectFamilyMemberList(FamilyMember familyMember);

    /**
     * 新增老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int insertFamilyMember(FamilyMember familyMember);

    /**
     * 修改老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int updateFamilyMember(FamilyMember familyMember);

    /**
     * 删除老人家属
     * 
     * @param id 老人家属主键
     * @return 结果
     */
    public int deleteFamilyMemberById(Long id);

    /**
     * 批量删除老人家属
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFamilyMemberByIds(Long[] ids);

    @Insert("insert into family_member_elder(id, family_member_id, elder_id, create_time, update_time, create_by, update_by, remark) values(#{id}, #{familyMemberId}, #{elderId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{remark})")
    void add(FamilyMemberEder familyMemberEder);
    List<FamilyMemberEder> my(Long userId);

    List<FamilyMemberVO> listByPage(Long userId);

    @Delete("delete from family_member_elder where id = #{id}")
    Integer deleteFamilyMemberElderById(Long id);
    /**
     * 按周统计查询指标数据
     * @param dto
     * @return
     */
    @Select("select DATE_FORMAT(alarm_time, '%m.%d') AS dateTime,dd.data_value as dataValue from device_data as dd  where function_id =#{functionId}  and UNIX_TIMESTAMP(alarm_time)* 1000 between #{startTime} and #{endTime}  group by dateTime")
    List<DeviceDataVoo> queryDeviceDataListByWeek(DeviceDataDto dto);
    /**
     * 按天统计查询指标数据
     * @param dto
     * @return
     */
    @Select("select DATE_FORMAT(alarm_time, '%H:00') AS dateTime,dd.data_value as dataValue from device_data as dd\n" +
            "where function_id = #{functionId}  and  UNIX_TIMESTAMP(alarm_time)* 1000 between #{startTime} and #{endTime} group by dateTime")
    List<DeviceDataVoo> queryDeviceDataListByDay(DeviceDataDto dto);
}
